package A12;

import java.util.List;

public class College {
    // 聚合关系：学院包含多个建筑
    private List<Building> buildings;
    // 组合关系：学院包含多个课程
    private List<Course> courses;

    public College(List<Building> buildings, List<Course> courses) {
        this.buildings = buildings;
        this.courses = courses;
    }

    // 添加建筑（聚合关系操作）
    public void addBuilding(Building building) {
        buildings.add(building);
    }

    // 添加课程（组合关系操作，校验约束）
    public void addCourse(Course course) {
        if (course.getBuilding() == null) {
            throw new IllegalArgumentException("约束：Course必须关联一个Building！");
        }
        courses.add(course);
    }

    // getter/setter
    public List<Building> getBuildings() {
        return buildings;
    }

    public List<Course> getCourses() {
        return courses;
    }
}
